package com.ruoyi.performance.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.performance.domain.PerfCheck;
import com.ruoyi.performance.domain.PerfCheckTypeSupplier;
import com.ruoyi.performance.domain.PerfLevelScore;
import com.ruoyi.performance.dto.PerfCheckTypeDto;
import com.ruoyi.performance.service.PerfCheckTypeService;
import com.ruoyi.performance.service.PerfLevelScoreService;
import com.ruoyi.performance.utils.MyUtils;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YL
 * @date 2020-07-22
 * @description 考核类别
 */
@RestController
@RequestMapping("checktype")
public class PerfCheckTypeController extends MyUtils {
	
	@Resource
	private PerfCheckTypeService perfCheckTypeService;

	/**
	 * 查询考核类别
	 *
	 * @param id 考核类别ID
	 * @return 考核类别
	 */
	@GetMapping("get/{id}")
	public R list(@PathVariable("id") int id){
		Map<String, Object> m = new HashMap<>(16);
		m.put("rows", perfCheckTypeService.selectPerfCheckTypeById(id));
		return R.ok(m);
	}
	/**
	 * 查询供应商
	 *
	 * @param checkTypeId 考核类别ID
	 * @return 考核类别
	 */
	@GetMapping("getvendor/{checkTypeId}")
	public R getvendor(@PathVariable("checkTypeId") int checkTypeId) {
		startPage();
		return result(perfCheckTypeService.selectPerfCheckTypeSupplierDtoById(checkTypeId));
	}

	/**
	 * 查询绩效等级分数区间列表
	 */
	@GetMapping("list")
	public R list(PerfCheckTypeDto perfCheckTypeDto) {
		startPage();
        return result(perfCheckTypeService.selectPerfCheckType(perfCheckTypeDto));
	}
	
	
	/**
	 * 新增保存绩效等级分数区间
	 */
	@PostMapping("save")
	public R addSave(@RequestBody PerfCheckTypeDto perfLevelScore) {
		return toAjax(perfCheckTypeService.insertPerfCheckType(perfLevelScore));
	}
	
	   /**
	    * 新增考核类别与供应商关系
	    *
	    * @param perfCheckTypeDto 考核类别
	    * @return 结果
	    */
	@PostMapping("saveVendor")
	   public Map<String,String> saveVendor(@RequestBody Map<String, List<PerfCheckTypeSupplier>> datas)
	   {
		return jacResultMsg(perfCheckTypeService.insertTypeVendor(datas));
	   }

	/**
	 * 修改保存绩效等级分数区间
	 */
	@PostMapping("update")
	public R editSave(@RequestBody PerfCheckTypeDto perfLevelScore) {
		return toAjax(perfCheckTypeService.updatePerfCheckType(perfLevelScore));
	}

	@PostMapping("remove")
	public Map<String, String> remove(String ids) {
		return jacResultMsg(perfCheckTypeService.deletePerfCheckType(ids));
	}
	
	   /**
	    * 删除考核类别与供应商关系
	    *
	    * @param id 考核类别
	    * @return 结果
	    */
	   @PostMapping("removeVencode")
	   public Map<String, String> removeVencode(String ids)
	   {
		   return jacResultMsg(perfCheckTypeService.deleteTypeVencode(ids));
	   }
	
}
